package com.jack.thinking.java._22.swing.pane;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

import com.utils.SwingConsole;

public class SimpleMenus extends JFrame{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JTextField t = new JTextField(15);
	private ActionListener al = new ActionListener() {
		@Override
		public void actionPerformed(ActionEvent e) {
			t.setText(((JMenuItem)e.getSource()).getText());
		}
	};
	
	private JMenu[] menus = {
			new JMenu("Winken"), new JMenu("Blinken"), new JMenu("Nod")
	};
	
	private JMenuItem[] items = {
			new JMenuItem("a1"), new JMenuItem("a2"), new JMenuItem("a3"),
			new JMenuItem("b1"), new JMenuItem("b2"), new JMenuItem("b3"),
			new JMenuItem("c1"), new JMenuItem("c2"), new JMenuItem("c3")
	};
	
	public SimpleMenus() {
		for(int i = 0; i < items.length; i++) {
			items[i].addActionListener(al);
			menus[i % 3].add(items[i]);
		}
		
		JMenuBar mb = new JMenuBar();
		for(JMenu jm : menus) {
			mb.add(jm);
		}
		setJMenuBar(mb);
		setLayout(new FlowLayout());
		add(t);
	}
	
	public static void main(String[] args) {
		SwingConsole.run(new SimpleMenus(), 200, 150);
	}
}
